package dryven.util.json;

import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Modifier;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import dryven.model.di.LocalThreadStorage;

public class GsonJsonEncoder implements JsonEncoder {

	private Gson _gson;
	
	@Override
	public void encodeRootValue(Object value, LocalThreadStorage diStorage, Appendable dest) {
		if(_gson==null) {
			_gson = new GsonBuilder()
				.serializeNulls()
				.excludeFieldsWithModifiers(Modifier.STATIC, Modifier.VOLATILE, Modifier.TRANSIENT)
				.create();
		}
		_gson.toJson(value, dest);
	}
}
